package com.xintonghua.bussiness.ui.user;

import android.os.Bundle;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xintonghua.base.ui.BaseActivity;
import com.xintonghua.base.utils.AllActivitiesHolder;
import com.xintonghua.base.widget.ConfirmDialog;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.api.manager.AuthManager;
import com.xintonghua.bussiness.util.GlideCacheUtil;
import com.xintonghua.bussiness.util.GlideUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity {

    @BindView(R.id.sw_alert)
    SwitchCompat swAlert;
    @BindView(R.id.sw_notify)
    SwitchCompat swNotify;
    @BindView(R.id.tv_cache)
    TextView tvCache;
    @BindView(R.id.ll_cache)
    LinearLayout llCache;
    @BindView(R.id.tv_exit)
    TextView tvExit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        onSimpleActionBar();
        setSimpleActionBar("设置");
        initUI();
    }

    @Override
    public void initUI() {
        super.initUI();
        swAlert.setTrackResource(R.drawable.switch_shape);
        swNotify.setTrackResource(R.drawable.switch_shape);
        tvCache.setText(GlideCacheUtil.getInstance().getCacheSize(this));
    }

    @OnClick({R.id.ll_cache, R.id.tv_exit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //清空缓存
            case R.id.ll_cache:
                ConfirmDialog.showDialog(this, "提示", "是否确定清除缓存？", "取消", "确定", null, new ConfirmDialog.OnRightListener() {
                    @Override
                    public void onClick(ConfirmDialog dialog) {
                        GlideCacheUtil.getInstance().clearImageAllCache(SettingActivity.this);
                        tvCache.setText("0.00M");
                    }
                });
                break;
            //退出账号
            case R.id.tv_exit:
                ConfirmDialog.showDialog(this, "提示", "是否确定退出账号？", "取消", "确定", null, new ConfirmDialog.OnRightListener() {
                    @Override
                    public void onClick(ConfirmDialog dialog) {
                        AllActivitiesHolder.finishAllAct();
                        openActivity(LoginActivity.class);
                        try {
                            AuthManager.destroy(SettingActivity.this);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
                break;
        }
    }
}
